<!--
 * @Author: Rachel 943701297@qq.com
 * @Date: 2022-07-08 10:38:14
 * @LastEditors: Rachel 943701297@qq.com
 * @LastEditTime: 2022-07-08 16:44:00
 * @FilePath: \JS\JSCode\鼠标移动.html
 * @Description: 
 * 
 * Copyright (c) 2022 by Rachel 943701297@qq.com, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>鼠标移动事件</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      #box {
        width: 100px;
        height: 100px;
        background-color: red;
      }
    </style>
    <script>
      window.onload = function () {
        let box = document.getElementById("box");
        document.onmousemove = (e) => {
          box.style.position = "absolute";
          box.style.left =
            e.clientX + document.documentElement.scrollLeft + "px";
          box.style.top = e.clientY + document.documentElement.scrollTop + "px";
        };
      };
    </script>
  </head>
  <body style="height: 1000px; width: 2000px">
    <div id="box"></div>
  </body>
</html>
